<?php

class Core_Action_Admin_System_Mail_Template_Add extends Action_Admin
{

	public function execute($request, $initial = FALSE, $script = NULL)
	{
		if ($initial)
		{
			Agilet::setVar('breadcrum', array(
				array(
					'url' => 'admin/system',
					'label' => 'System'
				),
				array(
					'url' => 'admin/system/mail/template',
					'label' => 'Mail Template'
				),
				array(
					'url' => 'admin/system/mail/template/edit',
					'label' => 'Add Template'
				)
			));

		}

		$table = Model::getTable('core/mail/template');

		$form = Form::factory('core/admin/mail/template');

		if ($request -> isGet())
		{
		}

		if ($request -> isPost() && $form -> isValid($_POST))
		{
			$data = $form -> getData();

			$item = $table -> fetchNew();

			$item -> fromArray($data);

			$item -> save();

			$form -> setNotice('Saved Successful!');
			
			Response::redirect('admin/system/mail/template');
		}

		$request -> response = View::render($script = 'core/html/admin/edit', $data = array(
			'form' => $form,
			'title' => 'Edit Mail Template'
		));
	}

}
